Postal details Rest API Design Document
Create a REST API which will accept customer Id as query parameter. Use that customer Id to fetch the data from Customer Database in order to get PIN code for that customer. Use this PIN code to get postal address details from India Post Rest API. Transform the response in the desired format to generate final response
Postal details Rest API:
Description:
It is an API which is used to get customer data from DB and use that data to get postal details from India Post API. We have the customer database and it has following no of columns in remote DB as shown below Customer’s table column name
Fields | Data Types |
---|---|
Id | Integer |
first_name | varchar |
last_name | varchar |
address | varchar |
pin | Integer |
varchar | |
login | varchar |
identifier | varchar |
End-Points:
SETP 1:
Login to Quick Integration Platform to get started.
;
STEP 2:
Click on Manage Option >> Projects >> Create to create the new project
;
;
Once project is created, below popup shows up.
;
STEP 3:
Go to DEVELOP >> Functionality API
;
STEP 4:
Select relevant project and create services in that project
;
;
STEP 5:
Once service name is provided, canvas will show up
;
STEP 6:
Left click on REST Trigger to Configure as given below.
;
Fields | Description | Examples |
---|---|---|
uri | Resource Path to trigger the API | /getPostalinfo |
type | Metods of The API like GET, PUT, PATCH, etc | GET |
STEP 7:
Drag UTILITY component to add start logger for you service.
;
STEP 8:
Left click on UTILITY Connector and Configure as given below.
;
Methods:
;
Log type:
;
Log Value:
Start Log - Start_level_log_info
STEP 9:
Drag URIVALIDATOR to validate the URL.
;
STEP 10:
Left click on URIVALIDATOR Connector and Configure as given below.
;
Fields | Description | Examples |
---|---|---|
Scenario-Name | Name of the scenario to be performed in case the validation failed. | Validate_request |
Request Params | Names of the param keys passed in query parameters. | ID |
STEP 11:
Drag DB Connector to make DB call in the service.
;
STEP 12:
Add DB connectivity details in Connection properties:
;
;
STEP 13:
Left click on DB Connector and Configure as given below. Select the database configuration created in properties to DB connectivity in datasource name:
;
Fields | Description | Example |
---|---|---|
DB Operation | Read/Write | Read |
Datasource Name | Datasource Name which is configured in connections properties | dbds |
Return Row(s) | Single, Multiple | Single |
Output Variable | This field is the variable name for which the output of the following step is store in the pipeline | Data |
Query | This is the Database commands | SELECT pin FROM crm_customers WHERE id=:id |
Let see how to write the query using quickintegration with few clicks
Select the table Name from the Droup down list, we can limit the number of records To be retrieved In filters add the condition for fields use in the query with the help of operation like NULL, NOT NULL, =, !=, etc Your Generated Query will get Created.
- Select the Table Name
;
- Select the Coloumn
;
- Select the Fields
;
- Select the Operations
;
Fields | Description | Example |
---|---|---|
Table Name | Data Base Table Name | crm_customers |
Your Generated Query is | Data Base Query | SELECT pin FROM crm_customers WHERE id:id |
Filters(Fields) | Perticular field where DB will Operate | id |
Filters(Operation) | Operations like NULL, NOT NULL, =, !=, etc | = |
STEP 14:
Define Global variables to be used in the service:
;
;
;
STEP 15:
Drag REST component to make India Post REST API call to get postal details based on PIN code.
;
STEP 16:
Left click on REST Connector and Configure as given below.
;
Fields | Description | Example |
---|---|---|
Http URL | URL by which the API will be called | dburl |
Method | Formats like GET, POST, DELETE, etc | GET |
Base Path | Resource Path | /pincode/;pincode |
Security | To be Defined in the propertioes like Basic Authentication, OAuth token, Authorization Code, etc | |
Output Variable | Stores output of connections operations | payload |
Type: pathparam
Target: pincode
key: $Data.pin
STEP 17:
Drag APIRESPONSE component to map the response :
;
Click on the Drop down and select Content Type application json
;
Click on Add button and do the mapping as shown below
When we want to get a variable, from the pipeline, we use $ sign as prefix followed by Variable name from in the pipeline. There can be nested get which is seperated by '.' Ex. $Payload.key.
Note:- The variable Payload should be present in the pipeline before the calling
;
;
Fields | Description |
---|---|
GEN | Get one field from the Input and mapped in another field of Output |
TRANS | Transforms the Input value with the help of transformation functions |
CN | Mapped the Input as it is Output body |
OBJ | Mapped the Inputs to Object |
AR | Mapped the Inputs to Array |
APIResponse Please refer the link for instructions on creating the APIResponse
STEP 18:
Drag UTILITY component to add end logger for you service
;
;
Methods:
;
Log type:
;
Log Value:
End Log - End_level_log_info
STEP 19:
Step Exception handling in the service:
Step error is specifically for particular connector error. Select the Step Exception handler from the palate, Drag it to the canvas and configure it for the DB and Rest error Please refer the configration shown below
;
;
Fields | Description | Example |
---|---|---|
Method | This is the utility function to throw the error in the flow | throw error |
Error Type | Type of Exception thrown in the flow such as INTBuinessException and INTRetryException | INTBuinessException |
Exception message | The custom message while throwing the custom Exception | $VARIABLES.nocustomer |
Exception code | The code while throwing the Execption | $VARIABLES.nocustomercode |
STEP 20:
;
If DB does not return response for a customer Id, error message is created as “No customer found”. PFB the configuration for reference:
;
Fields | Description | Example |
---|---|---|
Method | This is the utility function to throw the error in the flow | throw error |
Error Type | Type of Exception thrown in the flow such as INTBuinessException and INTRetryException | INTBuinessException |
Exception message | The custom message while throwing the custom Exception | $VARIABLES.invalidPin |
Exception code | The code while throwing the Execption | $VARIABLES.errorPin |
STEP 21:
Global Exception handling in the service:
Global Error is for the all the component in the flow. Select the Global Error from the palate, Drag it to the canvas and configure it as shown below
;
;
Fields | Description | Example |
---|---|---|
Method | This is the utility function to throw the error in the flow | throw error |
Error Type | Type of Exception thrown in the flow such as INTBuinessException and INTRetryException | INTBuinessException |
Exception message | The custom message while throwing the custom Exception | compulsory querry param not passed |
Exception code | The code while throwing the Execption | $VARIABLES.noid |
If any error occurs in the service during processing. It is handled in the global Exception handler.
STEP 22:
PFB the final service screenshot below :
;
STEP 23:
Step to Test the API Deployed on QuickIntegration.
- Save the application.
- Go to EXECUTE >> BUILD to Build the application.
- Deploy the application after build. Select the Application Name From Drop down, and pass the security key in Properties. Click on deploy application.
- Go to application and Bring UP the application by clicking on project.
- Provide the security key and start the API.
- Once you Successfully started your API, you will find Development URL in Details Coloumn
- Using the QuickIntegrate deployed URL You can Test your API using Postman Collection